<!DOCTYPE html>
<html lang="zh">

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>学习助手</title>
    <link rel="stylesheet" type="text/css" href="./static/bootstrap/css/bootstrap.min.css">

    <link rel="stylesheet" type="text/css" href="./static/css/style.css">
    <link rel="icon" href="./static/img/logo.png" type="image/png">
</head>
<style>
    .title_label {
        left: 8px;
        top: 10px;
        width: 100%;
        height: 19px;
        color: rgba(255, 255, 255, 1);
        font-size: 20px;
        text-align: left;
        font-family: PingFangSC-bold;
    }

    .header_main {
        width: 100%;
        margin: auto;
        background-image: url(/static/img/head_bg.png);
        background-position: top -140px right 0px;
        height: auto;
        padding: 10px;
        background-size: cover;
        background-size: 100%;
        background-repeat: no-repeat;
        color: dimgray;

    }

    .workStyle>li {
        float: left;
        margin-left: 10px;
        color: #fff;
        font-weight: 700;
    }

    #recordsListDiv {
        margin-top: 80px;
        font-size: medium;
        width: 100%;
    }


    #pswdInputForm>label {
        margin-top: 20px;
    }
</style>

<body id="mainAPP" class="header_main">
    <header id="home">

        <ul class="workStyle">
            <li>
                <!-- 今日，参数是当前时间往后退1天，所以参数天1 -->
                <button class="btn btn-success" onclick="window.location.href='/home'">个人信息 </button>

            </li>
            <li>
                <!-- 今日，参数是当前时间往后退1天，所以参数天1 -->
                <button class="btn btn-warning" onclick="window.location.href='/records'">加分记录 </button>

            </li>
            <li>
                <!-- 7天，参数是当前时间往后退7天，所以参数填7 -->
                <button class="btn btn-secondary" onclick="window.location.href='/fill'">填写加分 </button>
            </li>
        </ul>
    </header>
    <!-- 用户列表 div -->
    <div id="recordsListDiv">

    </div>
    <!-- 分页导航栏 -->

    <div style="position:fixed; bottom: 0px;left: 0; width: 100%;   background-color: #17ad74; " id="bottomBox">
        <div style="color: white; text-align: center;" id="userinfo">信息工程学院</div>
    </div>
    <script src="/static/bootstrap/js/bootstrap.min.js"></script>
    <script type="text/javascript" src="/static/js/axios.min.js"></script>
    <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/echarts/5.4.3/echarts.min.js"></script>

    <script type="text/javascript">
        function fillInfo() {
            let infoStr = sessionStorage.getItem("user");
            info = JSON.parse(infoStr);
            document.getElementById("userinfo").innerText = info.Classname + "." + info.Name;
        }
        fillInfo();
        // startNum 当前页的 开始数量
        function getDeviceList() {
            // 从session Storage 中获取token
            var jwt = sessionStorage.getItem("token");
            // 2. 使用axios 获取用户列表
            axios.get('/api/records/query',
                {
                    headers: { 'token': jwt },
                }).then(function (response) {
                    // 判断返回的数据是否正常
                    console.log(response);
                    if (response.status == 200) {
                        var recordsListDiv = document.getElementById('recordsListDiv');
                        // 用于存储 管理员用户列表的html  
                        if (response.data.code == 0) {
                            alert(response.data.data);
                            return
                        }
                        const allRecordList = response.data.data;
                        const snMap = new Map(); 
                        if (allRecordList) {
                            var allhtml = ``;
                            allRecordList.forEach(item => {
                                allhtml += `<form style="margin-top:0px" >    
                                    <label for="reseaon">科目:</label>《`+ item.CourseCn
                                    + `》 <label>得分:</label> <span style="color:red">` + item.Record + `</span> <br/>
                    <label for="reseaon">原因:</label>  <span id="reseaon">`+ item.Comments
                                    + `</span> <br/>  <label> 时间:</label>` + turnTime(item.Createtime) + `</div>
                           </form> <hr/>
                           `;
                            });
                            recordsListDiv.innerHTML = allhtml;

                        }
                    } else {
                        alert(response.data.data)
                    }

                }).catch(function (error) {
                    alert(error)
                });
        }
        getDeviceList();

        function turnTime(isoTime) {
            let date = new Date(isoTime);
            // 提取年、月、日、小时、分、秒
            let year = date.getFullYear();
            let month = ('0' + (date.getMonth() + 1)).slice(-2);
            let day = ('0' + date.getDate()).slice(-2);
            let hours = ('0' + date.getHours()).slice(-2);
            let minutes = ('0' + date.getMinutes()).slice(-2);
            let seconds = ('0' + date.getSeconds()).slice(-2);
            // 组合成指定格式的字符串
            return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
        }


    </script>

</body>

</html>